package net.tuanhiep1232.medicine.client;

import net.tuanhiep1232.medicine.client.model.BaseDto;
import net.tuanhiep1232.medicine.client.model.FolderDto;

import com.google.gwt.core.client.GWT;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.core.client.Style.LayoutRegion;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.TreeStore;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.TabItemConfig;
import com.sencha.gxt.widget.core.client.TabPanel;
import com.sencha.gxt.widget.core.client.container.AccordionLayoutContainer.AccordionLayoutAppearance;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
import com.sencha.gxt.widget.core.client.container.MarginData;

public class MainLayout extends Composite implements HasText {

	class KeyProvider implements ModelKeyProvider<BaseDto> {
		@Override
		public String getKey(BaseDto item) {
			return (item instanceof FolderDto ? "f-" : "m-")
					+ item.getId().toString();
		}
	}

	private static MainLayoutUiBinder uiBinder = GWT
			.create(MainLayoutUiBinder.class);

	interface MainLayoutUiBinder extends UiBinder<Widget, MainLayout> {
	}

	public MainLayout() {
		// northData.setMargins(new Margins(5));
		northData.setCollapsible(true);
		// westData.setMargins(new Margins(0, 5, 0, 5));
		westData.setCollapsible(true);
		westData.setCollapseMini(true);
		westData.setSplit(true);
		westData.setSize(250);
		westData.setFloatable(false);
		
		centerData.setMargins(new Margins(0));
		
		shortTextTabConfig.setClosable(true);
		shortTextTabConfig.setText("ABc");
		longTextTabConfig.setText("ABc");
		longTextTabConfig.setClosable(true);
		
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField(provided = true)
	String dummyTextShort = "dummyTextShort";
	/*
	 * @UiField(provided = true) AccordionLayoutAppearance
	 * accordionLayoutAppearance;
	 */

	@UiField(provided = true)
	TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());
	
	
	@UiField(provided = true)
	TabItemConfig shortTextTabConfig = new TabItemConfig();
	@UiField(provided = true)
	TabItemConfig longTextTabConfig = new TabItemConfig();

	@UiField(provided = true)
	MarginData outerData = new MarginData(0);
	@UiField(provided = true)
	BorderLayoutData northData = new BorderLayoutData(100);
	@UiField(provided = true)
	BorderLayoutData westData = new BorderLayoutData(150);
	@UiField(provided = true)
	MarginData centerData = new MarginData();
	@UiField(provided = true)
	BorderLayoutData eastData = new BorderLayoutData(150);
	@UiField(provided = true)
	BorderLayoutData southData = new BorderLayoutData(100);

	@UiFactory
	public ValueProvider<BaseDto, String> createValueProvider() {
		return new ValueProvider<BaseDto, String>() {

			@Override
			public String getValue(BaseDto object) {
				return object.getName();
			}

			@Override
			public void setValue(BaseDto object, String value) {
			}

			@Override
			public String getPath() {
				return "name";
			}
		};
	}
	
	@UiField
	protected ContentPanel menu;
	@UiField
	protected ContentPanel navigator;
	@UiField
	protected TabPanel tab;

	
	
	public ContentPanel getMenu() {
		return menu;
	}

	public void setMenu(ContentPanel menu) {
		this.menu = menu;
	}

	public ContentPanel getNavigator() {
		return navigator;
	}

	public void setNavigator(ContentPanel navigator) {
		this.navigator = navigator;
	}

	public TabPanel getTab() {
		return tab;
	}

	public void setTab(TabPanel tab) {
		this.tab = tab;
	}
	
	

	public String getText() {
		// TODO Auto-generated method stub
		return null;
	}

	public void setText(String arg0) {
		// TODO Auto-generated method stub

	}
}
